package com.cssy.authority.dao.impl;

import com.cssy.authority.dao.OrganizationDAO;
import com.cssy.authority.entity.Organization;
import com.cssy.authority.entity.OrganizationExample;
import com.ibatis.sqlmap.client.SqlMapClient;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class OrganizationDAOImpl implements OrganizationDAO {
    private SqlMapClient sqlMapClient;

    public OrganizationDAOImpl(SqlMapClient sqlMapClient) {
        super();
        this.sqlMapClient = sqlMapClient;
    }

    public void insert(Organization record) throws SQLException {
        sqlMapClient.insert("sc_organization.abatorgenerated_insert", record);
    }

    public int updateByPrimaryKey(Organization record) throws SQLException {
        int rows = sqlMapClient.update("sc_organization.abatorgenerated_updateByPrimaryKey", record);
        return rows;
    }

    public int updateByPrimaryKeySelective(Organization record) throws SQLException {
        int rows = sqlMapClient.update("sc_organization.abatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    public List selectByExample(OrganizationExample example) throws SQLException {
        List list = sqlMapClient.queryForList("sc_organization.abatorgenerated_selectByExample", example);
        return list;
    }

    public Organization selectByPrimaryKey(Long id) throws SQLException {
        Organization key = new Organization();
        key.setId(id);
        Organization record = (Organization) sqlMapClient.queryForObject("sc_organization.abatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    public int deleteByExample(OrganizationExample example) throws SQLException {
        int rows = sqlMapClient.delete("sc_organization.abatorgenerated_deleteByExample", example);
        return rows;
    }

    public int deleteByPrimaryKey(Long id) throws SQLException {
        Organization key = new Organization();
        key.setId(id);
        int rows = sqlMapClient.delete("sc_organization.abatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    public int countByExample(OrganizationExample example) throws SQLException {
        Integer count = (Integer)  sqlMapClient.queryForObject("sc_organization.abatorgenerated_countByExample", example);
        return count.intValue();
    }

    public int updateByExampleSelective(Organization record, OrganizationExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("sc_organization.abatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    public int updateByExample(Organization record, OrganizationExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("sc_organization.abatorgenerated_updateByExample", parms);
        return rows;
    }

    private static class UpdateByExampleParms extends OrganizationExample {
        private Object record;

        public UpdateByExampleParms(Object record, OrganizationExample example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }

}